package com.lizonghui.googleplay.control;

import android.view.View;
import android.widget.LinearLayout;

import com.lizonghui.googleplay.R;
import com.lizonghui.googleplay.base.BaseHolder;
import com.lizonghui.googleplay.utils.UIUtils;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/6/21.
 * 加载更多的holder数据泛型用Integer是因为一共就三种视图，都是固定的。根据数值可以判断显示哪种
 */
public class LoadingMoreHolder extends BaseHolder<Integer> {
    //泛型定义为数据类型，来决定UI的展现。
    //加载更多的视图，只有3中情况，所以之类用数据类型作为泛型

    public static final int LOADMORE_LOADING = 0;//正在加载
    public static final int LOADMORE_ERROR = 1;//加载错误
    public static final int LOADMORE_NONE = 2;//没有更多了


    @Bind(R.id.item_loadmore_container_loading)
    LinearLayout mItemLoadmoreContainerLoading;
    @Bind(R.id.item_loadmore_container_retry)
    LinearLayout mItemLoadmoreContainerRetry;

    @Override
    public void refreshHolderView(Integer data) {
        //首先应该设置全部隐藏
        mItemLoadmoreContainerLoading.setVisibility(View.GONE);
        mItemLoadmoreContainerRetry.setVisibility(View.GONE);
        switch (data) {
            case LOADMORE_LOADING:
                mItemLoadmoreContainerLoading.setVisibility(View.VISIBLE);
                break;
            case LOADMORE_ERROR:
                mItemLoadmoreContainerRetry.setVisibility(View.VISIBLE);
                break;
            case LOADMORE_NONE:
                break;
            default:
                break;
        }
    }

    @Override
    public View initHolderView() {
        View view = View.inflate(UIUtils.getContext(), R.layout.item_load_more, null);
        ButterKnife.bind(this, view);
        return view;
    }

}
